package it.datagraf.formazione.hellostruts.service;

import it.datagraf.formazione.hellostruts.dao.CompetenzaDaoI;
import it.datagraf.formazione.hellostruts.dao.CurriculumVitaeDaoI;
import it.datagraf.formazione.hellostruts.entity.Competenza;
import it.datagraf.formazione.hellostruts.entity.CurriculumVitae;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class CVserviceImpl implements CVServiceInteface {
	
	private CurriculumVitaeDaoI cvDao;
	private CompetenzaDaoI competenzaDao;
//	static Properties jdbcProps= new Properties();
//	static {
//		try {
//			jdbcProps.load(Class.class.getResourceAsStream("jdbc-connection.properties"));
//		} catch (IOException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//	}
	
	
	CurriculumVitaeDaoI getCvDao() throws SQLException {
		return cvDao;
	}
	
	
	public List<CurriculumVitae> listCvs() {
		List<CurriculumVitae> results=new ArrayList<CurriculumVitae>();
		CurriculumVitaeDaoI cvDao=null;
		try {
			results=getCvDao().list();
		} catch (SQLException e) {
			throw new RuntimeException(e);
		}finally {
			if(cvDao!=null)
				System.out.println("Sono nella classe CVServiceImpl - Metodo listCvs - Clausola finally - Mo so cazzi tua!!");
//				cvDao.closeConnection();
		}
		return results;
	}
	
	@Override
	public int saveCV(CurriculumVitae cv) {
		return this.cvDao.saveOrUpdate(cv);
	}


	public void setCvDao(CurriculumVitaeDaoI cvDao) {
		this.cvDao = cvDao;
	}


	@Override
	public int saveOrUpdateCompetenza(Competenza comp) {
		return competenzaDao.saveOrUpdate(comp);
	}


	@Override
	public Competenza getCompetenza(int id) {
		return competenzaDao.get(id);
	}


	public CompetenzaDaoI getCompetenzaDao() {
		return competenzaDao;
	}


	public void setCompetenzaDao(CompetenzaDaoI competenzaDao) {
		this.competenzaDao = competenzaDao;
	}


	@Override
	public CurriculumVitae find(CurriculumVitae cv) {
		return this.cvDao.find(cv);
	}
	
	@Override
	public CurriculumVitae find(int id) {
		return this.cvDao.find(id);
	}
	
	public int findId(String owner) {
		return this.cvDao.findId(owner);
	}

	public void remove(int id) {
		this.cvDao.remove(id);
	}


	public void removeComp(int id) {
		this.competenzaDao.removeComp(id);
	}

		

}
